home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / Kinokabra (RU).ifs < prev    next >
Text File  |  2005-04-09  |  8KB  |  259 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=LA (Andrey Lukyanov)       (<link>l_a@hotmail.ru</link>)
  8. Title=Kinokabra
  9. Description=Imports russian movies info with picture from Kinokabra.ru
  10. Site=http://kinokabra.ru/
  11. Language=RU
  12. Version=1.01 (27.03.2005)
  13. Requires=3.5.0
  14. Comments=
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program KinoKabra;
  23. const
  24.   BaseAddress = 'http://kinokabra.ru/';
  25. var
  26.   MovieName: string;
  27.   TempStr: string;
  28.  
  29. function ParseURL(Text:String):String;
  30. var
  31.   BeginPos : Integer;
  32.   EndPos : Integer;
  33.   Value : String;
  34. begin
  35.  
  36.   repeat
  37.     BeginPos := Pos('<b>',Text);
  38.     If BeginPos > 0 Then
  39.     Begin
  40.       EndPos := Pos('</b>',Text);
  41.       Value := copy(Text, BeginPos, EndPos - BeginPos);
  42.       Value := StringReplace(Value,'<BR>',', ');
  43.       Value := StringReplace(Value,'<br>',', ');
  44.       HTMLRemoveTags(Value);
  45.       Delete(Text,1,EndPos);
  46.       If Length(result)>0 Then
  47.         result := result + ', ' + Value
  48.       else
  49.         result := Value;
  50.     end;
  51.   until BeginPos < 1;
  52.  
  53. end;
  54.  
  55. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  56. var
  57.   i: Integer;
  58. begin
  59.   result := -1;
  60.   if StartAt < 0 then
  61.     StartAt := 0;
  62.   for i := StartAt to List.Count-1 do
  63.     if Pos(AnsiLowerCase(Pattern), AnsiLowerCase(List.GetString(i))) <> 0 then
  64.     begin
  65.       result := i;
  66.       Break;
  67.     end;
  68. end;
  69.  
  70. procedure AnalyzePage(Address: string);
  71. var
  72.   ID, FilmName, Line: String;
  73.   Page: TStringList;
  74.   FilmPage: TStringList;
  75.   BeginPos, EndPos, LineBeginPos: Integer;
  76. begin
  77.   Page := TStringList.Create;
  78.   // Page.SaveToFile('c:\page.txt'); // Σδ  ε≥δαΣΩΦ
  79.   // Page.LoadFromFile('c:\page.txt');
  80.   Page.Text := GetPage(Address);
  81.   PickTreeClear; // ╬≈Φ±≥Ωα Σσ≡σΓα ⌠Φδⁿ∞εΓ
  82.   PickTreeAdd('╨στ≤δⁿ≥α≥√ ∩εΦ±Ωα ⌠Φδⁿ∞α: ' + MovieName, '');
  83.   LineBeginPos := 0;
  84.   repeat
  85.     BeginPos := FindLine('<td><a href="film.php?id=', Page, LineBeginPos+1);
  86.     LineBeginPos := BeginPos;
  87.     if  BeginPos > 0 then
  88.       begin
  89.         // ┬√ΓεΣ ⌠Φδⁿ∞εΓ Γ Σσ≡σΓε
  90.         Line:= Page.GetString(BeginPos+1); // ╧εδ≤≈Φ≥ⁿ ±≥≡εΩ≤ ± αΣ≡σ±α∞Φ
  91.         repeat
  92.               BeginPos := Pos('<td><a href="film.php?id=',Line);
  93.               If BeginPos > 0 Then
  94.               // ∩εΦ±Ω Γετ∞εµφ√⌡ Γα≡Φαφ≥εΓ
  95.               Begin
  96.                 Delete(Line,1,Pos('<td>',Line)+3); //╙ΣαδσφΦσ φα≈αδα
  97.  
  98.                 // ∩εδ≤≈ασ∞ αΣ≡σ±
  99.                 BeginPos:=Pos('<a href="',Line)+9;
  100.                 EndPos := Pos('">',Line);
  101.                 ID := BaseAddress+copy(Line, BeginPos, EndPos - BeginPos); // ╧εδ≤≈Φ≥ⁿ αΣ≡σ± ±≥≡αφΦ÷√
  102.  
  103.                 // Γ√≥α±ΩΦΓασ∞ φατΓαφΦσ
  104.                 BeginPos := Pos('">',Line)+2;
  105.                 EndPos := Pos('</a>',Line);
  106.                 FilmName := Copy(Line, BeginPos, EndPos - BeginPos); // ╧εδ≤≈Φ≥ⁿ φατΓαφΦσ Σδ  Γ√ßε≡α
  107.                 FilmName := StringReplace(FilmName,' ',' ');
  108.                 PickTreeAdd(FilmName, ID);
  109.               end;
  110.         until BeginPos < 1;
  111.       end;
  112.    until LineBeginPos < 1;
  113.  
  114.   If  PickTreeExec(Address) Then
  115.       AnalyzeMoviePage(Address); // ╧≡εαφαδΦτΦ≡εΓα≥ⁿ ±≥≡αφΦ÷≤ ± ⌠Φδⁿ∞ε∞
  116. end;
  117.  
  118. procedure AnalyzeMoviePage(Address: String);
  119. var
  120.   Page: TStringList;
  121.   LineNr : Integer;
  122.   Line, Value, TmpStr : String;
  123.   BeginPos, EndPos : Integer;
  124.  
  125. begin
  126.   Page := TStringList.Create;
  127.   Page.Text := GetPage(Address);
  128.   //  Page.SaveToFile('c:\page2.txt'); // Σδ  ε≥δαΣΩΦ
  129.   // Page.LoadFromFile('c:\page2.txt');
  130.  
  131.   // URL
  132.   SetField(fieldURL,Address);
  133.  
  134.   //Rating
  135.  
  136.   // Translated Title
  137.   TmpStr := '<b>═ατΓαφΦσ ⌠Φδⁿ∞α:  </b>';
  138.   LineNr := FindLine(TmpStr, Page, 0);
  139.   if LineNr > -1 then
  140.   begin
  141.     Line := Page.GetString(LineNr);
  142.     BeginPos := Pos(TmpStr,Line)+Length(TmpStr);
  143.     EndPos := Pos(' / ',Line);
  144.     Line := Copy(Line, BeginPos, EndPos - BeginPos);
  145.     HTMLDecode(Line);
  146.     HTMLRemoveTags(Line);
  147.     Value := Trim(Line);
  148.     SetField(fieldTranslatedTitle,Value);
  149.  
  150.   // Original Title
  151.     Line := Page.GetString(LineNr);
  152.     BeginPos := Pos(' / ',Line)+3;
  153.     EndPos := Pos('</td></tr><tr>',Line);
  154.     Line := Copy(Line, BeginPos, EndPos - BeginPos);
  155.     HTMLDecode(Line);
  156.     HTMLRemoveTags(Line);
  157.     Value := Trim(Line);
  158.     if Value='' then Value := GetField(fieldTranslatedTitle);
  159.     SetField(fieldOriginalTitle, Value);
  160.  
  161.   // Year
  162.     Line := Page.GetString(LineNr);
  163.     TmpStr := '<u>';
  164.     BeginPos := Pos(TmpStr,Line)+Length(TmpStr)-1;
  165.     Delete(Line,1,BeginPos);
  166.     EndPos := Pos('</u>',Line);
  167.     Line := Copy(Line, 1, EndPos-1);
  168.     HTMLDecode(Line);
  169.     HTMLRemoveTags(Line);
  170.     Value := Trim(Line);
  171.     SetField(fieldYear, Value);
  172.  
  173.   //Category
  174.     Line := Page.GetString(LineNr);
  175.     TmpStr := '<b>╞αφ≡:  </b><a href="category.php?id=';
  176.     BeginPos := Pos(TmpStr,Line)+Length(TmpStr)-1;
  177.     Delete(Line,1,BeginPos);
  178.     TmpStr := '<u>';
  179.     BeginPos := Pos(TmpStr,Line)+Length(TmpStr)-1;
  180.     Delete(Line,1,BeginPos);
  181.     EndPos := Pos('  </td>',Line);
  182.     Line := Copy(Line, 1, EndPos-1);
  183.     HTMLDecode(Line);
  184.     HTMLRemoveTags(Line);
  185.     Line := StringReplace(Line,'  ',', ');
  186.     Value := Trim(Line);
  187.     SetField(fieldCategory, Value);
  188.  
  189.   //Country
  190.  
  191.   // Director
  192.     Line := Page.GetString(LineNr);
  193.     TmpStr := '<b>╨σµΦ±±σ≡:  </b>';
  194.     BeginPos := Pos(TmpStr,Line)+Length(TmpStr)-1;
  195.     Delete(Line,1,BeginPos);
  196.     EndPos := Pos('</td></tr>',Line);
  197.     Line := Copy(Line, 1, EndPos-1);
  198.     HTMLDecode(Line);
  199.     HTMLRemoveTags(Line);
  200.     Line := StringReplace(Line,'  ',', ');
  201.     Value := Trim(Line);
  202.     SetField(fieldDirector, Value);
  203.  
  204.   // Producer
  205.  
  206.   // Actors
  207.     Line := Page.GetString(LineNr);
  208.     TmpStr := '┬ ≡εδ ⌡:  </b>';
  209.     BeginPos := Pos(TmpStr,Line)+Length(TmpStr)-1;
  210.     Delete(Line,1,BeginPos);
  211.     EndPos := Pos('</p></td></tr>',Line);
  212.     Line := Copy(Line, 1, EndPos-1);
  213.     HTMLDecode(Line);
  214.     HTMLRemoveTags(Line);
  215.     Line := StringReplace(Line,'  ',', ');
  216.     Value := Trim(Line);
  217.     SetField(fieldActors, Value);
  218.  
  219.   // Description
  220.     Line := Page.GetString(LineNr);
  221.     TmpStr := '╬ ⌠Φδⁿ∞σ:  </b>';
  222.     BeginPos := Pos(TmpStr,Line)+Length(TmpStr)-1;
  223.     Delete(Line,1,BeginPos);
  224.     EndPos := Pos('</p></td></tr>',Line);
  225.     Line := Copy(Line, 1, EndPos-1);
  226.     Line := StringReplace(Line, '<br>', #13#10);
  227.     Line := StringReplace(Line, '<BR>', #13#10);
  228.     HTMLDecode(Line);
  229.     HTMLRemoveTags(Line);
  230.     Value := Trim(Line);
  231.     SetField(fieldDescription,Value);
  232.   end;
  233.  
  234.   // Picture
  235.   TmpStr := '<img border="0" src="images/films/';
  236.   LineNr := FindLine(TmpStr, Page, 0); // ═α≈αδε ±≥≡εΩΦ ± ≡Φ±≤φΩε∞
  237.   if LineNr > -1 then
  238.   begin
  239.     Line := Page.GetString(LineNr);
  240.     BeginPos := Pos('src="',Line)+4;
  241.     Delete(Line,1,BeginPos);
  242.     EndPos := pos('" ', Line);
  243.     Value := copy(Line, 1, EndPos-1);
  244.     Address := BaseAddress+Value;
  245.     GetPicture(Address);
  246.   end;
  247. // DisplayResults;
  248. end;
  249.  
  250. begin
  251.     MovieName := GetField(fieldOriginalTitle);
  252.     if MovieName = '' then
  253.       MovieName := GetField(fieldTranslatedTitle);
  254.     // MovieName := 'µσ±≥εΩΦσ'; // Σδ  ε≥δαΣΩΦ
  255.     if Input('╚∞∩ε≡≥ ± ±αΘ≥α Kinokabra.ru', '┬ΓσΣΦ≥σ φατΓαφΦσ ⌠Φδⁿ∞α:', MovieName) then
  256.       AnalyzePage(BaseAddress+'search.php?FilmTitle='+UrlEncode(MovieName));
  257.  
  258. end.
  259.